package middleware

import (
	"wonlicsys/utils/common"
	"github.com/gin-gonic/gin"
	"strconv"
)

func CheckInstanceId() gin.HandlerFunc {
	return func(c *gin.Context) {
		InstanceId := c.Request.Header.Get("InstanceId")
		if InstanceId == "" {
			common.JsonResult(c, 400, "InstanceId 错误", "fail")
			c.Abort()
			return
		}
		id, err := strconv.ParseUint(InstanceId, 10, 64)
		if !common.CheckId(id) || err != nil {
			common.JsonResult(c, 400, "InstanceId 错误", "fail")
			c.Abort()
			return
		}
		c.Set("InstanceId", InstanceId)
		c.Next()
	}

}

func CheckSign() gin.HandlerFunc {
	return func(c *gin.Context) {
		Sign := c.Request.Header.Get("Sign")
		if Sign == "" {
			common.JsonResult(c, 400, "Sign 不能为空", "fail")
			c.Abort()
			return
		}
		c.Set("Sign", Sign)
		c.Next()
	}

}
